package com.yc.demo.zy0301;

import com.google.gson.Gson;
import com.yc.demo.bean.Result;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "TJ3Servlet", value = "/TJ3Servlet")
public class TJ3Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 设置字符集
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        // 获取数据
        final String area = request.getParameter("area");
        // 获取会话
        HttpSession session = request.getSession();
        //
        session.setAttribute("area",area);
        //
        final Result result = new Result(1,"提交成功",null);
        //
        final Gson gson = new Gson();
        final String json = gson.toJson(result);
        response.getWriter().printf(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
